﻿/* ==============================================================================
 * 功能描述：TaskConfigProvider  
 * 
 * 创 建 者：郑镇泉
 * 
 * 创建日期：2016/4/21 11:11:40
 * ==============================================================================*/
using UnityEngine;
using System.Collections;

public class TaskConfigProvider : BaseProvider<TaskConfigProvider>
{
    private TaskConfig taskConfig;

    public TaskConfig TaskConfig
    {
        get
        {
            if (taskConfig == null)
            {
                taskConfig = LoadConfig<TaskConfig>("/xml/taskConfig.xml");
            }
            return taskConfig;
        }
    }

    public TaskConfigTask[] GetAll()
    {
        return TaskConfig.Items;
    }

    public TaskConfigTask GetTaskById(int id)
    {
        TaskConfigTask equip = System.Array.Find<TaskConfigTask>(TaskConfig.Items, (TaskConfigTask obj) =>
        {
            return int.Parse(obj.id) == id;
        });
        if (equip == null) Debug.Log("配置表中找不到该任务，id：" + id);
        return equip;
    }

    public TaskConfigTaskCondition GetTaskCondition(int taskId, int conditionId)
    {
        TaskConfigTask task = GetTaskById(taskId);
        TaskConfigTaskCondition condition = System.Array.Find(task.condition, ( obj) =>
        {
            return int.Parse(obj.id) == conditionId;
        });
        if(condition==null)Debug.Log("该任务中找不到这个条件，Id:"+conditionId);
        return condition;
    }

    public TaskConfigTaskReward GetTaskReward(int taskId, int rewardId)
    {
        TaskConfigTask task = GetTaskById(taskId);
        TaskConfigTaskReward condition = System.Array.Find(task.reward, (obj) =>
        {
            return int.Parse(obj.id) == rewardId;
        });
        if (condition == null) Debug.Log("该任务中找不到这个奖励，Id:" + rewardId);
        return condition;
    }
}